import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { Base } from "@/entities.base/base.entity";
import { Order } from "../order.entity";
import { Services } from "../services.entity";

@Entity({ comment: '订单服务明细表', name: 'basis_order_service' })
export class OrderService extends Base {

    /** 服务数量 */
    @Column({
        comment: '服务数量',
        type: 'int',
        default: 1,
    })
    quantity: number;

    /** 服务单价 */
    @Column({
        comment: '服务单价',
        type: 'decimal',
        precision: 10,
        scale: 2,
    })
    unitPrice: number;

    /** 服务总价 */
    @Column({
        comment: '服务总价',
        type: 'decimal',
        precision: 10,
        scale: 2,
    })
    totalPrice: number;

    /** 备注 */
    @Column({
        type: 'text',
        comment: '备注',
        nullable: true,
    })
    remark?: string;

    /** 关联的订单ID */
    @Column({
        comment: '订单ID',
        nullable: false,
    })
    orderId: string;

    /** 关联的服务ID */
    @Column({
        comment: '服务ID',
        nullable: false,
    })
    serviceId: string;

    /** 关联订单 - 多对一关系 */
    @ManyToOne(() => Order, order => order.services, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'orderId' })
    order: Order;

    /** 关联服务 - 多对一关系 */
    @ManyToOne(() => Services, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'serviceId' })
    service: Services;
} 